﻿@{
    Layout = "~/Views/Shared/_Layout_RTU_well.cshtml";
    ViewBag.Title = "井报警记录";
}
<div class="xds-no-breadcrumb">
    <div class="full-height">
        <div class="full-height-scroll white-bg border-left">
            <div class="wrapper wrapper-content animated fadeInRight">
                <div class="row">
                    <div class="col-md-12">
                        <div class="panel panel-primary" id="list-panel">
                            <div class="panel-heading">
                                <h1 class="panel-title">报警记录</h1>
                            </div>
                            <div class="panel-body">
                                <table id="assets-data-table" class="table table-striped table-bordered" style="width:100%"></table>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal inmodal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
                    <div class="modal-dialog" style="width:300px">
                        <div class="modal-content animated bounceInRight">
                            <div class="modal-header" style="padding:0">
                                <h4 class="modal-title">报警通知</h4>
                            </div>
                            <div class="modal-body" style="padding:5px 2px 5px 30px;height:150px">
                                <div id="workercontainer" class="mapcontainer" style="width:260px;height:130px;left:20px">
                                    <select id="Options" style="margin: 22px 0 12px 0; width: 260px;">
                                        <option></option>
                                    </select>
                                    <div id="informinformation"  style="margin: 22px 0 12px 0; width: 260px; height:20px">
                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer clear" style="width:100%">
                                <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="makeinform()">确定</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@section Styles {
    @Styles.Render("~/Content/datatables")
    @Styles.Render("~/plugins/sweetAlertStyles")
}

@section Scripts {
    @Scripts.Render("~/bundles/datatables")
    @Scripts.Render("~/plugins/sweetAlert")
    <script type="text/javascript">
        var assetListVM;
        assetListVM = {
            dt: null,
            reload: function () {
                dt.ajax.url("@Url.Action("GetWarn", "WarnLog")" + "?wellid=" + sessionStorage.wellid).load();
            },
            init: function () {
                dt = $("#assets-data-table").DataTable({
                    "serverSide": true,
                    "proccessing": true,
                    "ajax": {
                        "url": "@Url.Action("GetWarn","WarnLog")" + "?wellid=" + sessionStorage.wellid
                    },
                    "order": [[ 2, 'desc' ]],
                    "columns": [
                        //{ "title": "报警记录ID", "data": "ID", "searchable": true },
                        //{ "title": "井号", "data": "WELL_ID", "searchable": true },
                        { "title": "报警信息", "data": "Describe", "searchable": true },
                        { "title": "报警开始时间", "data": "ActionTime" },
                        { "title": "报警结束时间", "data": "ErrorEndTime" },
                        { "title": "报警记录状态", "data": "YorN", "searchable": true },
                        { "title": "操作", "data": null }
                    ],
                    "columnDefs": [{
                        // 定义操作列,######以下是重点########
                        "targets": 4,//操作按钮目标列
                        "data": null,
                        //"render": function (data, type, row, meta) {
                        //    return '<a type="button"  href="#" onclick="del()" >删除</a>';
                        //}
                        "render": function (data, type, row) {
                            var id = data.ID;
                            var wellid = data.WELL_ID;
                            var html = '<a type="button"  href="#"  onclick="inform(' + id + ',' + wellid + ')" class="btn btn-primary" data-toggle="modal" data-target="#myModal">通知</a>';
                            html += '<a type="button"  href="#" onclick="ignore('+id+','+wellid+')" class="btn btn-primary" style="margin-left:10px">忽略</a>';
                            return html;
                        }
                    }],
                    "lengthMenu": [[10, 25, 50, 100], [10, 25, 50, 100]],
                    "language": {
                        "processing": "处理中...",
                        "lengthMenu": "显示 _MENU_ 项结果",
                        "zeroRecords": "没有匹配结果",
                        "info": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                        "infoEmpty": "显示第 0 至 0 项结果，共 0 项",
                        "infoFiltered": "(由 _MAX_ 项结果过滤)",
                        "infoPostFix": "",
                        "search": "搜索:",
                        "searchPlaceholder": "搜索...",
                        "url": "",
                        "emptyTable": "表中数据为空",
                        "loadingRecords": "载入中...",
                        "infoThousands": ",",
                        "paginate": {
                            "first": "首页",
                            "previous": "上页",
                            "next": "下页",
                            "last": "末页"
                        },
                        "aria": {
                            paginate: {
                                first: '首页',
                                previous: '上页',
                                next: '下页',
                                last: '末页'
                            },
                            "sortAscending": ": 以升序排列此列",
                            "sortDescending": ": 以降序排列此列"
                        },
                        "decimal": "-",
                        "thousands": ","
                    }
                });
            }
        };
        $(document).ready(function () {
            assetListVM.init();
        });
        function inform(id, wellid) {
            GetOptions(wellid,id);
        }
        function ignore(id,wellid) {
            //alert("忽略" + id);
            $.ajax({
                url: "/WarnLog/IgnoreWarn",
                method: 'GET',
                dataType: 'json',
                data: { wellid: id },
                async: false,
                success: function (data) {
                    if (data.status == 7) {
                        swal({
                            title: "Welcome in Alerts!",
                            text: "Authority error."
                        });
                    }
                    else if (data.status == 0) {
                       
                        alert("忽略" + wellid + "号井的报警成功");
                    }
                },
                error: function () {
                    swal({
                        title: "Welcome in Alerts!",
                        text: "The connection between server and units is not very stable. For any technical assistant, please call 1-(517)-927-5910."
                    });

                }
            });
        }

        function makeinform() {
        }
        function GetOptions(wellid,id) {
            $("#Options").empty();
            $("#informinformation").empty();
            $("#workercontainer").attr("value", id);
            $("<option></option>")
            .val("0")
            .text("请选择-")
            .appendTo($("#Options"));
            $.ajax({
                url: "/WarnLog/GetOnesWorker",
                method: 'GET',
                dataType: 'json',
                data: { wellid: wellid },
                async: false,
                success: function (result) {
                    $.each(result.data, function (i, item) {
                        $("<option></option>")
                        .val(item.PhoneNumber)
                        .text(item.UserName)
                        .appendTo($("#Options"));
                    });
                    $("#Options").change(function () {
                        var id = $('#workercontainer').attr("value");
                        var name = $('#Options option:selected').text();
                        var phone = $('#Options option:selected').val();
                        var s = "将" + id + "号错误通知" + name + ",电话：" + phone;
                        $("#informinformation").empty();
                        $("<div>"+ s+"</div>").appendTo($("#informinformation"));
                    });
                }
            });
        }
    </script>
}
